<?php
//error_reporting(E_ALL);
//就近 www.jiujin.me
global $_W, $_GPC;
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($operation == 'display'){
        ca('user_article.list.view');
	$pindex = max(1, intval($_GPC['page']));
	$psize = 20;
        $condition="";
        $params=array();
        if (!empty($_GPC['nickname'])) {
            $_GPC['nickname'] = trim($_GPC['nickname']);
            $condition .= ' and ( m.nickname like :nickname )';
            $params[':nickname'] = "%{$_GPC['nickname']}%";
        }
        if (!empty($_GPC['status']) || $_GPC['status']==="0") {
            $condition .= ' and a.status=:status';
            $params[':status'] = intval($_GPC['status']);
        }
        $list = pdo_fetchAll("SELECT a.*,m.nickname,m.avatar  FROM " . tablename('activity_article') . " a left  join " . tablename('ewei_shop_member') . " m on a.openid=m.openid and a.uniacid=m.uniacid" . " WHERE a.uniacid=m.uniacid  $condition order by a.id desc",$params);
        foreach($list as $key => $value){
            $list[$key]['article_img']="http://wx.lanxuevip.com/attachment/".$value['article_img'];
            $list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
            if($value['visittime']){
            $list[$key]['visittime'] = date('Y-m-d H:i:s',$value['visittime']);
            }else{
            $list[$key]['visittime']=""; 
            }
        }
        $total = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('activity_article') . " WHERE  uniacid = '{$_W['uniacid']}' ORDER BY id DESC");
        $pager = pagination($total, $pindex, $psize);
}
if ($operation == 'agree'){
        ca('user_article.list.view');
	$pindex = max(1, intval($_GPC['page']));
	$psize = 20;
        $condition="";
        $params=array();
        $list = pdo_fetchAll("SELECT a.*,m.nickname,m.avatar  FROM " . tablename('activity_article') . " a left  join " . tablename('ewei_shop_member') . " m on a.openid=m.openid and a.uniacid=m.uniacid" . " WHERE a.status=1  $condition order by a.visittime desc",$params);
        foreach($list as $key => $value){
            $list[$key]['article_img']="http://wx.lanxuevip.com/attachment/".$value['article_img'];
            $list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
            if($value['visittime']){
            $list[$key]['visittime'] = date('Y-m-d H:i:s',$value['visittime']);
            }else{
            $list[$key]['visittime']=""; 
            }
        }
        $total = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('activity_article') . " WHERE  uniacid = '{$_W['uniacid']}' ORDER BY id DESC");
        $pager = pagination($total, $pindex, $psize);
}
if($operation == 'shenghe'){
    ca('user_article.list.add');
    ca('user_article.list.edit');
    if(!empty($_GPC['select']) && !empty($_GPC['id'])){
        pdo_update("activity_article",array('status'=>$_GPC['select'],'visittime'=>time()),array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
        message('审核成功！', $this->createWebUrl('article/list'));
    }
}
if($operation == 'detail'){
  ca('user_article.list.view');
  $id=$_GPC['id'];
  if(empty($id)){
     exit; 
  }
  $info=pdo_fetch('select * from '.tablename('activity_article')." where uniacid=:uniacid and id=:id ",array(':uniacid'=>$_W['uniacid'],':id'=>$id));
  $authorinfo=pdo_fetch('select * from '.tablename('ewei_shop_member')." where uniacid=:uniacid and openid=:openid ",array(':uniacid'=>$_W['uniacid'],':openid'=>$info['openid']));
  $info['article_content']=htmlspecialchars_decode($info['article_content']);
  $info['createtime']=date('Y-m-d H-i-s',$info['createtime']);
  $info['author']=$authorinfo['nickname'];
  $info['author_id']=$authorinfo['id'];
  $info['image']="http://wx.lanxuevip.com/attachment/".$info['article_img'];
}
load()->func('tpl');
include $this->template('web/article/list');